
<form role="form" class="epii" method="post" data-form="1" action="{url card_preferential add_edit }">
    <span id="box">
        {if empty($info)}
        <div class="form-group" style="margin-right: 15px">
            <label style="min-width: 15%">充值：</label>
            <input type="number" class="form-control" name="r[recharge_money][]" value=""
                   placeholder="请输入充值金额" required >
            <label style="min-width: 15%">赠送：</label>
            <input type="number" class="form-control" name="r[gift_money][]" value=""
                   placeholder="请输入赠送金额" required>
            <div class="input-group-append" style="margin-left: 10px;">
                <button class="btn btn-outline-secondary" type="button"  onclick="addGz()"><i class="fa fa-plus"></i></button>
            </div>
        </div>
        {else}
            {foreach $info as $k=>$v}
                <div class="form-group" style="margin-right: 15px">
                    <label style="min-width: 15%">充值：</label>
                    <input type="number" class="form-control" name="r[recharge_money][]" value="{$v.recharge_money}"
                           placeholder="请输入充值金额" required >
                    <label style="min-width: 15%">赠送：</label>
                    <input type="number" class="form-control" name="r[gift_money][]" value="{$v.gift_money}"
                           placeholder="请输入赠送金额" required>
                    <div class="input-group-append" style="margin-left: 10px;">
                        {if $k==0}
                        <button class="btn  btn-success" type="button"  onclick="addGz()"><i class="fa fa-plus"></i></button>
                        {else}
                        <button class="btn  btn-danger" type="button"  onclick="del($(this))"><i class="fa fa-minus"></i></button>
                        {/if}
                    </div>
                </div>
            {/foreach}
        {/if}

    </span>
    <input type="hidden" name="card_cate_id" value="{$card_cate_id?0}">
    <div class="form-footer" >
        <button type="submit" class="btn btn-primary">提交</button>
    </div>
</form>
<script>

    function addGz() {
        var html = $("#box>.form-group:last").clone();
        console.log(html);
        //清除input value 值
        html.find('input').val('');
        // //将添加按钮改为删除按钮
        html.children('.input-group-append').remove()
        html.append('<div class="input-group-append" style="margin-left: 10px;"><button class="btn btn-danger" type="button"  onclick="del($(this))"><i class="fa fa-minus"></i></button> </div>')
        $('#box').append(html);
    }
    function del(obj) {
        let count=$('#box').children('.form-group').length
        if(count>1){
            layer.confirm('确定要删除吗？',function (index) {
                layer.close(index);
                obj.parent().parent().remove();
            })

        }
    }


</script>
